<template>
    <div>
        <button @click="getStudents">获取接口学生数据</button><br><br>
        <button @click="getCars">获取接口汽车数据</button>
        <hr>
        <button @click="getLocalStudents">获取本地学生数据</button>
    </div>
</template>

<script>
    import axios from 'axios'
    export default {
        name: 'App',
        methods: {
            getStudents(){
                //发送请求
                axios.get('http://localhost:8080/api-students/students').then(  //服务端接口：http://localhost:5000/students 
                    response => {
                        console.log('请求接口students成功了：', response.data);

                    }, 
                    error => {
                        console.log('请求接口students失败了：', error.message);
                    }
                    )
            },
            getCars(){
                //发送请求
                axios.get('http://localhost:8080/api-cars/cars').then(  //服务端接口：http://localhost:5001/cars
                    response => {
                        console.log('请求接口cars成功了：', response.data);

                    }, 
                    error => {
                        console.log('请求接口cars失败了：', error.message);
                    }
                    )
            },
            getLocalStudents(){
                //发送请求
                axios.get('http://localhost:8080/students').then(  //本地接口：http://localhost:8080/students 
                    response => {
                        console.log('请求本地students成功了：', response.data);

                    }, 
                    error => {
                        console.log('请求本地students失败了：', error.message);
                    }
                    )
            }
        }

    }
</script>
